<template>
    <van-icon
        :color="likeCount ? '#ffa500' : '#777'"
        :name="likeCount ? 'good-job' : 'good-job-o'"
        @click="btnLike"
    />
</template>

<script>
import { addLike, deleteLike } from "@/api/articles";
export default {
    name: "LikeArticle",
    props: {
        ["like-count"]: {
            type: Number,
            required: true,
        },
        id: {
            type: [String, Number],
            required: true,
        },
    },
    methods: {
        async btnLike() {
            // 调用两个接口
            if (this["like-count"]) {
                // 删除点赞
                await deleteLike(this.id);
            } else {
                await addLike(this.id);
            }
            // 暴露事件
            this.$emit("update:like-count", this.likeCount ? 0 : 1);
        },
    },
};
</script>